package eduware.util.crypt;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Writer;

import eduware.util.exception.ChaocipherException;

/**
 * This class provides a BufferedWriter that is extended by an encryption
 * support basing on Chaocipher.
 * 
 * @author Florian Bausch
 * 
 */
public class EncryptedWriter extends BufferedWriter {

	/**
	 * An instance of Chaocipher for encrypting the file.
	 */
	private Chaocipher cc;

	/**
	 * Creates an EncryptedWriter.
	 * 
	 * @param arg0
	 *            A writer.
	 * @throws ChaocipherException 
	 */
	public EncryptedWriter(Writer arg0) throws ChaocipherException {
		super(arg0);
			cc = new Chaocipher();
	}

	/**
	 * Writes a String into the Writer after encrypting it.
	 * 
	 * @throws IOEXception
	 */
	public void write(String line) throws IOException {
		super.write(cc.encrypt(line));
	}

	public void newLine() throws IOException {
		super.write(cc.encrypt("\r\n"));
	}

}
